package club.janna.jrpc.serialize.json;

import club.janna.jrpc.annotation.SPIService;
import club.janna.jrpc.serialize.Serialization;
import com.alibaba.fastjson.JSONObject;

@SPIService("json")
public class JsonSerialization implements Serialization {
    @Override
    public byte[] serialize(Object object) {
        return JSONObject.toJSONString(object).getBytes();
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> tClass) {
        return JSONObject.parseObject(new String(bytes), tClass);
    }
}
